package org.ax.service.plan.imple;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.ax.mapper.plan.ProductMapper;
import org.ax.pojo.plan.Product;
import org.ax.service.plan.ProductService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 编程人:赵浩鑫
 * 时间:2021-02-25-14:42
 */
@Service
public class IProductService extends ServiceImpl<ProductMapper, Product> implements ProductService {
    @Override
    public Page<Product> findProductList(Page page, String productName, String status) {
        QueryWrapper<Product> queryWrapper=new QueryWrapper<Product>();
        queryWrapper.like(!StringUtils.isBlank(productName), "productName", productName);
        queryWrapper.like(!StringUtils.isBlank(status), "status", status);
        return getBaseMapper().selectPage(page, queryWrapper);
    }

    @Override
    public boolean addProduct(Product product) {
        return getBaseMapper().insert(product)>0;
    }

    @Override
    public boolean updProduct(Product product) {
        return getBaseMapper().updateById(product)>0;
    }

    @Override
    public boolean deletesProduct(String[] ids) {
        return getBaseMapper().deleteBatchIds(Arrays.asList(ids))>0;
    }

    @Override
    public Product toProductId(String id) {
        return getBaseMapper().selectById(id);
    }

    @Override
    public List<Product> availableProduct() {
        return getBaseMapper().selectList(null);
    }
}
